import 'dart:io';

import 'package:flutter/material.dart';
import 'package:getwidget/getwidget.dart';
import 'package:images_picker/images_picker.dart';
import 'package:meal/constant/sizes.dart';
import 'package:meal/utils/colors.dart';
import 'package:meal/utils/styles.dart';
import 'package:meal/utils/tools.dart';

class ContractStore extends StatefulWidget {
  const ContractStore({Key? key}) : super(key: key);

  @override
  State<ContractStore> createState() => _ContractStoreState();
}

class _ContractStoreState extends State<ContractStore> {
  List<Media> opposite = [];

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: ToolsUtils.getDefaultBackgroundColor(),
      appBar: ToolsUtils.getDefaultBrnAppBar('签订合同'),
      body: SizedBox(
        height: double.maxFinite,
        child: SingleChildScrollView(
          child: Column(
            children: [
              Container(
                  decoration: const BoxDecoration(color: Colors.white),
                  padding: const EdgeInsets.only(
                      left: Sizes.default10, top: Sizes.default10, bottom: Sizes.default10),
                  child: Column(
                    children: [
                      Container(
                        alignment: Alignment.centerLeft,
                        child: Text(
                          '恭喜您！您的开店申请已经通过线下审核。',
                          style: StylesUtils.customTextStyle(color: ColorsUtils.color797),
                        ),
                      ),
                      Container(
                        alignment: Alignment.centerLeft,
                        child: Text(
                          '请继续完成最后的合同签订工作，以便您能正式在平台上开店营业。',
                          style: StylesUtils.customTextStyle(color: ColorsUtils.color797),
                        ),
                      )
                    ],
                  )),
              Container(
                margin: const EdgeInsets.only(top: Sizes.default15),
                padding: const EdgeInsets.all(Sizes.default10),
                decoration: const BoxDecoration(color: Colors.white),
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    Expanded(
                        child: Container(
                      alignment: Alignment.centerLeft,
                      padding: const EdgeInsets.only(right: Sizes.default10),
                      child: Text('请下载打印小默外卖商家签约合同，填写完整并加盖企业公章后拍照上传。',
                          style: StylesUtils.customTextStyle(
                              fontSize: Sizes.default15, color: ColorsUtils.color333)),
                    )),
                    SizedBox(
                      width: 110,
                      height: Sizes.default40,
                      child: GFButton(
                          onPressed: () {},
                          text: '下载合同',
                          textStyle: StylesUtils.customTextStyle(fontSize: Sizes.default16),
                          shape: GFButtonShape.pills,
                          type: GFButtonType.solid,
                          size: GFSize.LARGE,
                          color: ColorsUtils.parseColorFromHexString(ColorsUtils.colorFf6)),
                    ),
                  ],
                ),
              ),
              Container(
                margin: const EdgeInsets.only(top: Sizes.default15),
                padding: const EdgeInsets.symmetric(vertical: Sizes.default10),
                decoration: const BoxDecoration(color: Colors.white),
                child: Column(
                  children: [
                    Container(
                      width: 345,
                      constraints: const BoxConstraints(minHeight: 205),
                      alignment: Alignment.center,
                      decoration: BoxDecoration(color: ColorsUtils.rgba(247, 247, 247, 1)),
                      child: Column(
                        children: [
                          Container(
                            padding: const EdgeInsets.only(top: Sizes.default50),
                            alignment: Alignment.center,
                            child: Wrap(
                              spacing: Sizes.default10,
                              runSpacing: Sizes.default10,
                              crossAxisAlignment: WrapCrossAlignment.center,
                              children: [
                                ...opposite.map((e) => GFImageOverlay(
                                    image: FileImage(File(e.path)), width: 100, height: 100)),
                                GestureDetector(
                                  onTap: uploadImg,
                                  child: SizedBox(
                                      height: 46,
                                      width: 46,
                                      child: ToolsUtils.getUrlSvg(
                                          'https://cdn7.axureshop.com/demo/1525603/images/2门店信息/u579.svg')),
                                )
                              ],
                            ),
                          ),
                        ],
                      ),
                    ),
                    Container(
                      height: Sizes.default50,
                      decoration: const BoxDecoration(color: Colors.white),
                      alignment: Alignment.center,
                      child: Text('证件背面图(照片面)',
                          style: StylesUtils.customTextStyle(
                              fontSize: Sizes.default15, color: ColorsUtils.color333)),
                    ),
                  ],
                ),
              )
            ],
          ),
        ),
      ),
      bottomNavigationBar: SafeArea(
        top: false,
        child: Container(
            height: Sizes.default60,
            alignment: Alignment.topCenter,
            padding: const EdgeInsets.symmetric(vertical: Sizes.default10),
            decoration: const BoxDecoration(color: Colors.white),
            child: SizedBox(
              height: Sizes.default40,
              child: FractionallySizedBox(
                widthFactor: 0.9,
                child: GFButton(
                    onPressed: () {
                      // Get.toNamed(RouteGet.storeFlow);
                    },
                    text: '提交审核',
                    textStyle: StylesUtils.customTextStyle(fontSize: Sizes.default16),
                    shape: GFButtonShape.pills,
                    type: GFButtonType.solid,
                    size: GFSize.LARGE,
                    color: ColorsUtils.parseColorFromHexString(ColorsUtils.colorFf6)),
              ),
            )),
      ),
    );
  }

  void uploadImg() {
    ToolsUtils.openGalleryOrCamera(context, (res) {
      uploadFilePath(res);
    }, (resp) {
      uploadFilePath(resp);
    });
  }

  void uploadFilePath(List<Media> res) {
    opposite.addAll(res);
    setState(() {});
  }
}
